<template>
  <div class="editAudit">
    <el-form :model="editAuditForm" :rules="editAuditRules" v-loading="editAuditLoading" ref="editAuditRefs" class="editAuditCls">
      <el-form-item prop="failMsg">
        <el-input
          type="textarea"
          :rows="4"
          placeholder="请输入未通过原因"
          v-model="editAuditForm.failMsg">
        </el-input>
      </el-form-item>
      <div class="subBtnWid">
        <el-button size="small" type="primary" @click="submitAudit('editAuditRefs')" :loading="loadingBtn">提交</el-button>
      </div>
    </el-form>
  </div>
</template>

<script>
  import {
    putApplyAuditApi
  } from '@/api/financial';

  export default {
    name: "index",
    props: {
      id: {
        type: [Number, String],
        id: 0
      }
    },
    data() {
      return {
        editAuditLoading: false,
        loadingBtn: false,
        editAuditForm: {
          failMsg: ''
        },
        editAuditRules: {
          failMsg: [
            { required: true, message: '请输入不通过原因', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      submitAudit(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            this.$set(this, 'loadingBtn', true);
            putApplyAuditApi(this.id, {
              status: 2,
              failMsg: this.editAuditForm.failMsg
            }).then(res => {
              this.$message.success('新增成功');
              this.$emit('getAuditList');
              this.$emit('close');
              this.$set(this, 'loadingBtn', false);
            }).catch(() => {
              this.$set(this, 'loadingBtn', false);
            });
          } else {
            return false;
          }
        });
      }
    }
  }
</script>

<style scoped>

</style>
